package cn.stylefeng.guns.modular.ums.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.ums.entity.RobotLog;
import cn.stylefeng.guns.modular.ums.mapper.RobotLogMapper;
import cn.stylefeng.guns.modular.ums.model.params.RobotLogParam;
import cn.stylefeng.guns.modular.ums.model.result.RobotLogResult;
import  cn.stylefeng.guns.modular.ums.service.RobotLogService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 智能聊天记录 服务实现类
 * </p>
 *
 * @author yzb
 * @since 2022-05-26
 */
@Service
public class RobotLogServiceImpl extends ServiceImpl<RobotLogMapper, RobotLog> implements RobotLogService {

    @Override
    public void add(RobotLogParam param){
        RobotLog entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(RobotLogParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(RobotLogParam param){
        RobotLog oldEntity = getOldEntity(param);
        RobotLog newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public RobotLogResult findBySpec(RobotLogParam param){
        return null;
    }

    @Override
    public List<RobotLogResult> findListBySpec(RobotLogParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(RobotLogParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(RobotLogParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private RobotLog getOldEntity(RobotLogParam param) {
        return this.getById(getKey(param));
    }

    private RobotLog getEntity(RobotLogParam param) {
        RobotLog entity = new RobotLog();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
